package com.example.basic.web.controller.pharm;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.basic.core.result.Result;
import com.example.basic.core.result.ResultGenerator;
import com.example.basic.custom.Log;
import com.example.basic.web.model.pharm.Pharm;
import com.example.basic.web.service.pharm.PharmService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@Api(value  = "仓库管理", tags = {"仓库管理"})
@RestController
@RequestMapping("/api/v1/byg/pharm")
public class PharmController {

    @Resource
    private PharmService pharmService;

    @Log(title = "仓库管理", description = "新增或修改")
    @ApiOperation(value = "新增或修改", notes = "新增或修改")
    @PostMapping("/addOrUpdate")
    public Result<Pharm> addOrUpdate(@ApiParam(name = "pharm", value = "模型", required = true) @RequestBody Pharm pharm) {
        return ResultGenerator.genSuccessResult(pharmService.addOrUpdate(pharm));
    }

    @Log(title = "仓库管理", description = "详情")
    @ApiOperation(value = "详情", notes = "详情")
    @PostMapping("/detail")
    public Result<Pharm> detail(@ApiParam(name = "pharmCode", value = "仓库编码") @RequestParam String pharmCode) {
        return ResultGenerator.genSuccessResult(pharmService.detail(pharmCode));
    }

    @Log(title = "仓库管理", description = "删除")
    @ApiOperation(value = "删除", notes = "删除")
    @PostMapping("/delete")
    public Result<Integer> delete(@ApiParam(name = "pharmCode", value = "仓库编码") @RequestParam String pharmCode ) {
        return ResultGenerator.genSuccessResult(pharmService.delete(pharmCode));
    }

    @Log(title = "仓库管理", description = "启用/禁用")
    @ApiOperation(value = "启用/禁用", notes = "启用/禁用")
    @PostMapping("/enableOrDisable")
    public Result<Integer> enableOrDisable(@ApiParam(name = "pharmCode", value = "仓库编码") @RequestParam String pharmCode) {
        return ResultGenerator.genSuccessResult(pharmService.enableOrDisable(pharmCode));
    }

    @Log(title = "仓库管理", description = "列表")
    @ApiOperation(value = "列表", notes = "列表")
    @PostMapping("/queryList")
    public Result<IPage<Pharm>> queryList(
            @ApiParam(name = "searchParam", value = "模糊搜索(拼音码,五笔码,名称,编码)") @RequestParam(required = false) String searchParam,
            @ApiParam(name = "isAll", value = "是否查询全部 0-否，1-是") @RequestParam(defaultValue = "0") String isAll,
            @ApiParam(name = "page", value = "页数，list分页的第几页") @RequestParam(defaultValue = "0") Integer page,
            @ApiParam(name = "size", value = "条数，list分页的每页条数") @RequestParam(defaultValue = "0") Integer size) {
        Page<Pharm> queryPage = new Page<>(page,size);
        return ResultGenerator.genSuccessResult(pharmService.queryList(queryPage,searchParam, isAll));
    }
}
